home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
optivc16
/
vdemow1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-06
|
10KB
|
255 lines
/***************************** VDEMOW1.CPP *****************************
* *
* Demo program for *
* V e c t o r L i b *
* for Borland C++ for Windows *
* with OWL 1.0 (shipped with Borland C++ versions 3.0 and 3.1) *
* *
* Copyright 1996-1998 by Martin Sander *
* *
* *
* This sample program is meant to demonstrate how to use *
* VectorLib within your Windows programs. It is not intended *
* to demonstrate best Windows programming. *
* *
**************************************************************************/
/* The include-file search path must contain
\bc\include; \bc\classlib\include; \bc\owl\include; \bc\optivec\include
The library search path must contain
\bc\lib; bc\classlib\lib; bc\owl\lib; bc\optivec\lib
You must build a project with the following entries:
\bc\optivec\vdemow1.cpp
\bc\optivec\lib\vcl3w.lib
\bc\owl\lib\owl.def
(If your Borland C++ directory has a name other than "bc",
you must use that other name, of course)
Additionally, you have to link in the class libraries, ObjectWindows,
and the standard run-time libraries (use Options/Linker/Libraries)
*/
#define WIN30
#include <owl.h>
#include <VFstd.h>
#include <VCFstd.h>
#include <VFmath.h>
#include <VIstd.h>
#include <VCFmath.h>
#include <Vgraph.h>
#include <math.h>
#include <string.h>
#include <float.h>
NEWMATHERR
class TVecApp : public TApplication
{
public:
TVecApp(LPSTR AName, HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
: TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
virtual void InitMainWindow();
};
_CLASSDEF(TVecWindow)
class TVecWindow : public TWindow
{
public:
fVector X1, X2, Y1, Y2, Y3, Y4, Spc, Freq, Win;
cfVector CX1, CX2;
iVector I1;
ui vsize, spcsize;
int vview;
struct time tStart, tStop;
TVecWindow(PTWindowsObject AParent, LPSTR ATitle);
~TVecWindow();
virtual void Paint(HDC DC, PAINTSTRUCT& PS);
virtual void WMRButtonDown(RTMessage Msg)
= [WM_FIRST + WM_RBUTTONDOWN];
void StartTime( void );
double StopTime( void );
};
TVecWindow::TVecWindow(PTWindowsObject AParent, LPSTR ATitle)
: TWindow(AParent, ATitle)
{
vsize = 1025;
spcsize = 128;
vview = 0;
I1 = VI_vector( vsize );
X1 = VF_vector( vsize );
X2 = VF_vector( vsize );
Y1 = VF_vector( vsize );
Y2 = VF_vector( vsize );
Y3 = VF_vector( vsize );
Y4 = VF_vector( vsize );
Spc= VF_vector( spcsize+1 );
Freq=VF_vector( spcsize+1 );
Win= VF_vector( 2*spcsize );
CX1 = VCF_vector( vsize );
CX2 = VCF_vector( vsize );
}
TVecWindow::~TVecWindow()
{
V_nfree( 12, I1, X1, X2, Y1, Y2, Y3, Y4, CX1, CX2, Spc, Freq, Win );
}
void TVecWindow::WMRButtonDown(RTMessage /*Msg*/)
{
InvalidateRect(HWindow, NULL, TRUE);
switch( vview )
{
default: vview=-1;
case 0: VF_ramp( X1, vsize, 0, 80*M_PI/vsize );
VF_ramp( Freq, spcsize+1, 0, (vsize / (80*M_PI)) / spcsize );
/* get a time axis from 0 to 80 Pi and a corresponding
frequency axis from 0 to the Nyquist frequency */
VF_sin( Y1, X1, vsize );
// get a simple sine wave
break;
case 1: VF_cmp_gtC( Y2, Y1, vsize, 0.7 );
// transform the sine into an asymmetric square wave
break;
case 2: VF_Hanning( Win, 2*spcsize );
Spc[spcsize] = VFs_spectrum( Spc, spcsize, Y2, vsize, Win );
// analyse the frequency spectrum of the square wave
break;
case 3: VI_ramp( I1, vsize, 0, 1 );
VF_ramp( X1, vsize, 0, 4.0 /(vsize-1) );
VF_sinrpi2( Y1, I1, vsize, (vsize-1)/2);
VFx_equV( Y1, Y1, vsize, 10.0, 20.0 );
VF_tanrpi2( Y2, I1, vsize, (vsize-1)/2);
VF_limit( Y2, Y2, vsize, -40, 40 );
VF_cosecrpi2( Y3, I1, vsize, (vsize-1)/2);
VF_limit( Y3, Y3, vsize, -40, 40 );
VF_subC( Y3, Y3, vsize, 20.0 );
break;
case 4: VCF_ramp( CX1, vsize, fcplx( M_PI, 0 ),
fcplx( 0.04, 0.0001 ));
VCF_cos( CX2, CX1, vsize );
VCF_sin( CX1, CX1, vsize );
/* Try also with other complex functions! */
break;
case 5: break;
}
vview++;
}
void TVecWindow::Paint(HDC DC, PAINTSTRUCT&)
{
char Explanation[100];
unsigned i, j;
float xt, A=1.2, B=-0.13, C=0.85;
V_initPlot( HWindow, DC );
switch( vview )
{
default: break;
case 0: TextOut( DC, 10, 10,
"This is a series of graphs illustrating VectorLib functions.", 60 );
TextOut( DC, 10, 40,
"Always press the right mouse button to see the next view!", 56 );
TextOut( DC, 10, 70,
"Press [Alt] [F4] to end the demonstration.", 41 );
break;
case 1: TextOut( DC, 0, 10, "Portion of a", 12 );
TextOut( DC, 0, 30, "Sine wave", 9 );
VF_xyAutoPlot( X1, Y1, vsize/4, PS_SOLID, LIGHTRED );
break;
case 2: TextOut( DC, 0, 10, "Asymmetric", 10 );
TextOut( DC, 0, 30, "square wave", 11 );
V_drawAxes( 0, vsize/4, -0.3, 1.2 );
VF_yDataPlot( Y2, vsize/4, PS_SOLID, BLUE );
break;
case 3: TextOut( DC, 0, 10, "Frequency spectrum", 18 );
TextOut( DC, 0, 30, "of the square wave", 18 );
TextOut( DC, 0, 150, "Don't be sur-", 13 );
TextOut( DC, 0, 170, "prised; the next", 16 );
TextOut( DC, 0, 190, "example will show", 17 );
TextOut( DC, 0, 210, "a bit of error", 14 );
TextOut( DC, 0, 230, "handling!", 9 );
VF_xyAutoPlot( Freq, Spc, spcsize+1, PS_SOLID | SY_CROSS, GREEN );
break;
case 4: TextOut( DC, 0, 10, "Trigonometric", 13 );
TextOut( DC,10, 30, "functions:", 10 );
TextOut( DC, 0, 50, "Red: sine", 11 );
TextOut( DC, 0, 70, "Green: tangent", 14 );
TextOut( DC, 0, 90, "Blue: cosecant", 15 );
TextOut( DC, 0, 120, "(sine:", 6 );
TextOut( DC, 0, 140, " *10 and +20,", 15 );
TextOut( DC, 0, 160, " cosecant: -20)", 15 );
VF_xy2AutoPlot( X1, Y2, vsize, PS_SOLID, LIGHTGREEN,
X1, Y3, vsize, PS_SOLID, LIGHTBLUE );
VF_xyDataPlot( X1, Y1, vsize, PS_SOLID, LIGHTRED );
break;
case 5: TextOut( DC, 0, 10, "Playing with functions", 22 );
TextOut( DC, 0, 30, "in the complex plane:", 21 );
TextOut( DC, 0, 60, "Red: complex sine", 19 );
TextOut( DC, 0, 80, "Green: complex cosine", 21 );
VCF_2AutoPlot( CX1, vsize, PS_SOLID, LIGHTRED,
CX2, vsize, PS_SOLID, LIGHTGREEN );
break;
case 6: TextOut( DC, 0, 10, "To end the demo, let's make a crude speed comparison", 52 );
TextOut( DC, 0, 30, "between compiled code and VectorLib code.", 41 );
V_nfree( 2, X1, X2 );
X1 = VF_vector( 4096 );
VF_ramp( X1, 4096, -10, 0.005 );
X2 = VF_vector( 4096 );